import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect:'/pre'
    },
    {
      //简介界面
      path: '/pre',
      name: 'PrePage',
      component: () => import('../views/pre/PrePage.vue'),
    },
    {
      //简介界面
      path: '/info',
      name: 'PreInfo',
      component: () => import('../views/pre/PreInfo.vue'),
    },
    {
      //登录界面
      path: '/login',
      name: 'LoginApp',
      component: () => import('../views/login/LoginApp.vue'),
      meta: {
        name: '登录'
      }
    },
    {
      path: '/auth',
      name: 'LoginAuth',
      component: () => import('../views/login/LoginAuth.vue'),
    },
    {
      //异常界面
      path: '/error/:err',
      name: 'ErrorPage',
      component: () => import('../views/error/ErrorPage.vue'),
    },
    {
      path: '/:pathMatch(.*)', redirect: '/error/404', name: "notMatch", hidden: true
    }

  ]
})
//全局路由守卫，解决路由跳转后滚动条不在顶部问题
router.beforeEach((to, from, next) => {
  window.scrollTo(0, 0)
  // console.log('scroll to top')
  next()
})
export default router
